package base

import (
	"context"
	basePb "git.mycaigou.com/gfyx/micro-gfyx-oppty-service/proto/micro_gfyx_oppty_service_proto/micro-gfyx-oppty-service/base"
	"git.mycaigou.com/gfyx/micro-gfyx-oppty-service/service/base/site"
)

type siteServer struct {
	siteService site.SiteServiceIface
}

func NewSiteServer(siteService site.SiteServiceIface) basePb.SiteServiceServer {
	return &siteServer{
		siteService: siteService,
	}
}

// SaveSiteInfo 保存站点信息
func (s *siteServer) SaveSiteInfo(ctx context.Context, request *basePb.SaveSiteInfoRequest) (*basePb.SaveSiteInfoResponse, error) {
	//if request.GetSiteInfo() != nil && request.GetSiteInfo().GetLogo() == "" {
	//	return nil, errors.New("logo不能为空")
	//}
	if err := s.siteService.SaveSiteInfo(ctx, request); err != nil {
		return nil, err
	}
	return &basePb.SaveSiteInfoResponse{IsSuccess: true}, nil
}

// GetSiteInfo 获取站点信息
func (s *siteServer) GetSiteInfo(ctx context.Context, request *basePb.GetSiteInfoRequest) (*basePb.GetSiteInfoResponse, error) {
	siteInfo, err := s.siteService.GetSiteInfo(ctx)
	if err != nil {
		return nil, err
	}
	return &basePb.GetSiteInfoResponse{SiteInfo: &basePb.SiteInfo{Logo: siteInfo.Logo}}, nil
}
